package String;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        String str1="hello";
        String str2="hello";
        System.out.println(str1==str2);
        String str3=new String("hello");
        System.out.println(str1==str3);
        String str4=str3.intern();
        System.out.println(str4==str3);
        System.out.println(str4==str1);

        String str5="abc";
        String str6="abc";
        System.out.println(str5.equals(str6));
        String str7="ABC";
        System.out.println(str5.compareTo(str7));
        System.out.println(str5.compareToIgnoreCase(str7));

        String str8="abcdabcd";
        System.out.println(str8.charAt(2));//char charAt(int index)
        System.out.println(str8.indexOf("abc"));//int indexOf
        System.out.println(str8.lastIndexOf("abc"));//int LastIndexOf
        //valueof方法调用toString方法
        //数字转字符串用valueof
        String str9=String.valueOf(23838);
        System.out.println(str9);
        //字符串转数字
        int data1=Integer.parseInt("3748");
        double data2=Double.parseDouble("323.09");
        System.out.println(data2);

        //大小写转换toUpperCase toLowerCase
        //注意是创建新对象储存改变大小写之后的
        String str10="abc";
        String str11=str10.toUpperCase();
        System.out.println(str10);//abc
        System.out.println(str11);//ABC

        //字符串转数组toCharArray
        char[] str12=str10.toCharArray();
        System.out.println(Arrays.toString(str12));//[a, b, c]

        //format
        System.out.println(String.format("%d/%d/%d",2025,3,24));//2025/3/24

        //替换
        //创建新对象Java中不能对数组直接修改
        String str13="aaaa bbbb";
        System.out.println(str13.replace('a','c'));//ccccbbbb
        System.out.println(str13.replaceFirst("a","c"));//caaabbbb
        //spilt分割
        String[] arr=str13.split(" ");
        for(String a:arr){
            System.out.println(a);//aaaa
                                  //bbbb
        }
        //特殊字符字符"|" "*" "."前面要加"//"
    }
}
